<?php

namespace plugin\admin\app\model;

use plugin\admin\app\model\BaseThink;
/**
 * @property integer $id 主键(主键)
 * @property string $name 角色名
 * @property string $rules 规则
 * @property string $created_at 创建时间
 * @property string $updated_at 更新时间
 */
class AdminRoleThink extends BaseThink
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_admin_roles';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $pk = 'id';

    public function admins(){
        return $this->belongsToMany(AdminThink::class,'admin_access','admin_id','role_id');
    }

    public function getRoleFormatSelect(){
        $data = $this->where('status','>',-1)->select();
        $select = [
            'type'=>'select',
            "multiple"=> true,
            'options'=>[]
        ];
        foreach ($data as $vo){
            $select['options'][] = [
                'label'=>$vo['name'],
                'value'=>$vo['id']
            ];
        }
        return $select;
    }
    public function getRoles(){
        $map = [
            ['id','<>',1],
            ['status','=',1],
        ];
        $data = $this->where($map)->select();
        return $data;
    }
}
